package org.example.travel_web.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.travel_web.dto.PageResult;
import org.example.travel_web.dto.category.PageReq;
import org.example.travel_web.dto.category.PageResp;
import org.example.travel_web.entity.RouteCategoriesET;
import org.example.travel_web.mapper.RouteCategoriesMapper;
import org.example.travel_web.service.RouteCategoriesService;
import org.springframework.stereotype.Service;

/**
 * @author 23591
 * @description 针对表【travel_route_categories(用于存储旅游路线的分类信息)】的数据库操作Service实现
 * @createDate 2025-01-21 15:58:07
 */
@Service
public class RouteCategoriesServiceImpl extends ServiceImpl<RouteCategoriesMapper, RouteCategoriesET>
        implements RouteCategoriesService {

    @Override
    public PageResult<PageResp> pageResult(PageReq req) {
        LambdaQueryWrapper<RouteCategoriesET> queryWrapper = new LambdaQueryWrapper<>();
        if (StrUtil.isNotBlank(req.getKeyword())) {
            queryWrapper.like(RouteCategoriesET::getName, req.getKeyword());
        }
        queryWrapper.orderByDesc(RouteCategoriesET::getCategoryId);
        Page<RouteCategoriesET> page = page(new Page<>(req.getPage(), req.getSize()), queryWrapper);
        return PageResult.of(page.getTotal(), page.getCurrent(), page.getSize(), BeanUtil.copyToList(page.getRecords(), PageResp.class));
    }
}




